package LOG;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Logger {
	private static Logger instance;
	/**
	 * Constructor to only create an object  of Logger
	 */
	private Logger(){
	}
	/**
	 * Method to get Instance of Logger
	 * @return Instance of Logger
	 */
	public static Logger getInstance() 
	{
		if (instance == null)
			instance = new Logger();
		return instance;
	}
	/**
	 * Method to write new log message into Console
	 * @param log_string new log message
	 */
	static public void writeLog(String log_string){
		// get the current time 
		String now=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
		String log_message =  now +" "+ log_string;
		System.out.println(log_message);
		try {
			File f = new File("Log.txt");		
			BufferedWriter bw = new BufferedWriter( new FileWriter(f,true));
			bw.write(log_message);
			bw.newLine();
			bw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
}
